package com.heaven1949.tmall.common.web.exception;

import cn.hutool.core.util.StrUtil;
import com.heaven1949.tmall.common.core.dto.IResultCode;
import com.heaven1949.tmall.common.core.dto.ResultCode;

/**
 * @author zhangjian
 * @date 2023-03-10 09:42:14
 */
public class TmallException extends RuntimeException {

    private IResultCode resultCode;
    private String error;

    public IResultCode getResultCode() {
        return resultCode;
    }

    public String getError() {
        return StrUtil.isBlank(this.error) ? super.getMessage() : error;
    }

    public TmallException(IResultCode resultCode) {
        super((resultCode.getMsg()));
        this.resultCode = resultCode;
    }

    public TmallException(IResultCode resultCode, String... params) {
        super(resultCode.getMsg());
        this.resultCode = resultCode;
    }

    public TmallException(IResultCode resultCode, Throwable throwable) {
        super(resultCode.getMsg(), throwable);
        this.resultCode = resultCode;
    }

    public TmallException(String error, Throwable throwable) {
        super(ResultCode.SYSTEM_EXECUTION_ERROR.getCode(), throwable);
        this.error = error;
    }

    public TmallException(String error, IResultCode resultCode) {
        this(resultCode);
        this.error = error;
    }

    public TmallException(String error) {
        this(ResultCode.SYSTEM_EXECUTION_ERROR);
        this.error = error;
    }

}
